home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7994 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Example using vfprintf
  5. Date: 29 Feb 1996 18:39:03 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4h5gv8$fvs@solutions.solon.com>
  8. References: <raffelmDnK19L.IH6@netcom.com> <raffelmDnK2ww.39r@netcom.com>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <raffelmDnK2ww.39r@netcom.com>,
  12. Matt Raffel <raffelm@netcom.com> wrote:
  13.  
  14. >void lprintf(char *pszFormat, ...)
  15. >{
  16. >   FILE *pstFile = NULL;
  17. >   va_list pstMarker;
  18.  
  19. This highlights the basic brokenness of the faux Hungarian botch Microsoft
  20. encourages.  What kind of idiot would use "pst" for something which is
  21. a "char *"?  Oh, wait, you mean it's a long on your system, and a pointer
  22. to struct on another system, and just a plain struct on another?  Gee,
  23. maybe it's *an opaque type*, and you should never pretend to know what's in
  24. it.
  25.  
  26. The only sane "type prefix" for a va_list would be something like va, or
  27. v_l.
  28.  
  29. And, of course, I agree with both GNU and Rob Pike - mixed case variable
  30. names like ICantReadThis are *stupid*.  If you want non-breaking spaces,
  31. use underscore, which is a non-breaking space.
  32.  
  33. >   va_start(pstMarker);
  34. >   pstFile = fopen("llog.txt", "wt+");
  35.  
  36. !!!
  37. This is almost certainly *NOT* what you want:
  38. 1.  The "t" mode flag is meaningless - except for the fact that it causes
  39. any further text (such as the "+") to be ignored.
  40. 2.  The + is meaningless; why indicate update (read/write) when you don't
  41. plan to write?
  42. 3.  THE 'w' FLAG WILL TRUNCATE THE FILE ON OPEN!  This is *NOT* good for
  43. a logging feature.
  44.  
  45. >   if (pstFile)
  46. >   {
  47. >      vfprintf(pstFile, pszFormat, pstMarker);
  48. >      fclose(pstFile);
  49. >   }
  50. >   va_end(pstMarker);
  51. >}
  52.  
  53. Apart from the poor naming, this is probably correct.
  54.  
  55. -s
  56. -- 
  57. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  58. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  59. FUCK the communications decency act.  Goddamned government.  [literally.]
  60. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  61.